package com.cskaoyan.service.admin.system;

import com.cskaoyan.bean.MarketLog;
import com.cskaoyan.bean.MarketLogExample;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketLogMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author erdonc
 * @date 2022/9/8 19:25
 * @description: TODO
 */
@Service
public class LogServiceImpl implements LogService {
    @Autowired
    MarketLogMapper logMapper;


    @Override
    public CommonData<MarketLog> list(BasePageInfo info, String name) {
        // 开启分页
        PageHelper.startPage(info.getPage(), info.getLimit());
        // 设置查询条件
        MarketLogExample example = new MarketLogExample();
        example.setOrderByClause(info.getSort() + " " + info.getOrder());
        MarketLogExample.Criteria criteria = example.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (!StringUtils.isEmpty(name)) {
            criteria.andAdminLike("%" + name + "%");
        }
        List<MarketLog> marketLogs = logMapper.selectByExample(example);
        PageInfo<MarketLog> pageInfo = new PageInfo<>(marketLogs);
        return CommonData.data(pageInfo);
    }
}
